﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://wubiyu.cnblogs.com">
<head>
    <title>Finance</title>
    <script type="text/javascript" src="Scripts/domExt.js"></script>
    <script type="text/javascript" src="Scripts/json2.min.js"></script>
    <script type="text/javascript" src="Scripts/Share.js"></script>
</head>
<body id="body" style="display: none;">
    <h:layout borderwidth="0,0,0,0">
        <h:head id="hdbox" hposition="0,0,*,60" borderwidth="0,0,0,0">
            <div id="mnav">
                <h:btn isactive="true">&nbsp;&nbsp;记帐&nbsp;&nbsp;</h:btn>
                <h:btn css="splitbtn" csshover="splitbtnhover">|</h:btn>
                <h:btn>&nbsp;&nbsp;报表&nbsp;&nbsp;</h:btn>
                <h:btn css="splitbtn" csshover="splitbtnhover">|</h:btn>
                <h:btn>&nbsp;&nbsp;账户&nbsp;&nbsp;</h:btn>
                <h:btn css="splitbtn" csshover="splitbtnhover">|</h:btn>
                <h:btn>&nbsp;&nbsp;设置&nbsp;&nbsp;</h:btn>
            </div>
            <div class="loginarea">
            </div>
        </h:head>
        <h:bottom id="btbox" hposition="0,0,*,*">
            <h:layout borderwidth="8,8,8,0" style="border-color: transparent;">
                <h:left id="lfbox" hposition="0,0,220,*" borderwidth="0,0,0,0">
                    <h:layout borderwidth="0,8,8,8" style="border-color: transparent;">
                        <h:head hposition="0,0,*,30" borderwidth="0,0,1,0" style="z-index: 1;">
                            <div id="lnav">
                                <h:btn id="transferBillbtn" isactive="false" keychar="shift+T">转帐</h:btn>
                                <h:btn id="addBillbtn" isactive="false" keychar="shift+A">添加</h:btn>
                                <h:btn id="delBillbtn">删除</h:btn>
                                <h:btn id="hidleftbtn"><<</h:btn>
                            </div>
                            <div id="addBillContent" style="display: none;">
                                <div class="content">
                                    <div class="msg" id="addBillMsg" style="height: 0px; overflow: hidden;">
                                        <li class="ico"></li>
                                        <li id="addBillMsgText">请填写分类。</li>
                                    </div>
                                    <br />
                                    每天一记，让生活更精彩！
                                    <br />
                                    <br />
                                    操作：<h:editdroplist id="OperationEidt" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="readonly"></h:editdroplist><br />
                                    <br />
                                    金额：<h:text id="MoneyTxt" text="0.0"></h:text><br />
                                    <br />
                                    分类：<h:editdroplist id="CategoryEdit" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="false" dropboxheight="215"></h:editdroplist><br />
                                    <br />
                                    项目：<h:editdroplist id="ProjectEdit" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="readonly"></h:editdroplist><br />
                                    <br />
                                    帐户：<h:editdroplist id="AccountEdit" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="readonly"></h:editdroplist><br />
                                    <br />
                                    <h:text id="MarkTxt" text="备注：" istextarea="true">
                                    </h:text>
                                    <br />
                                    <br />
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h:btn id="addBillOk" keychar="Enter"
                                        keygroup="addBillContent">保存 (Enter)</h:btn>&nbsp;<h:btn id="addBillEsc" keychar="ESC"
                                            keygroup="addBillContent">关闭 (Esc)</h:btn>
                                </div>
                            </div>
                            <div id="CreateTransferAccounts" style="display: none;">
                                <div class="content">
                                    <div class="msg" id="transferMsg" style="height: 0px; overflow: hidden;">
                                        <li class="ico"></li>
                                        <li id="transferMsgText">请填写分类。</li>
                                    </div>
                                    <br />
                                    每天一记，让生活更精彩！
                                    <br />
                                    <br />
                                    金额：<br />
                                    <br />
                                    <h:text id="TransferMoneyTxt" text="0.0"></h:text>
                                    <br />
                                    <br />
                                    出账帐户：<br />
                                    <br />
                                    <h:editdroplist id="OutAccountEdit" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="readonly" dropboxheight="104">
                                    </h:editdroplist><br />
                                    <br />
                                    入账帐户：<br />
                                    <br />
                                    <h:editdroplist id="InAccountEdit" itemtemplet="&nbsp;{=Name}" textdatatemplet="{=Name}"
                                        textisreadonly="readonly" dropboxheight="52">
                                    </h:editdroplist>
                                    <br />
                                    <br />
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <h:btn id="TransferOk" keychar="Enter" keygroup="CreateTransferAccounts">保存 (Enter)</h:btn>&nbsp;<h:btn
                                        id="TransferEsc" keychar="ESC" keygroup="CreateTransferAccounts">关闭 (Esc)</h:btn>
                                </div>
                            </div>
                        </h:head>
                        <h:bottom id="lmenu" borderwidth="1,0,0,0">
                            <div id="UserNameLab" style="margin: 5px 0px 0px 5px;">
                            </div>
                            <div id="ProjectListLab" style="margin: 0px 0px 0px 20px;">
                                <h:listview id="ProjectList" ismultiselect="true">
                                    <h:itemtemplet>
                                         &nbsp;{=Name}
                                    </h:itemtemplet>
                                </h:listview>
                            </div>
                            <div id="AccountLab">
                                银行：
                            </div>
                            <div id="AccountPanel">
                                <h:listview id="AccountList" ismultiselect="true">
                                    <h:itemtemplet>
                                         &nbsp;{=Name}
                                    </h:itemtemplet>
                                </h:listview>
                            </div>
                        </h:bottom>
                    </h:layout>
                </h:left>
                <h:vsplitter id="leftVsplitter" hposition="0,0,0,0" borderwidth="0,0,0,0" dragenabled="false">
                    <h:btn id="showleftbtn">>></h:btn>
                </h:vsplitter>
                <h:right id="rtbox" borderwidth="1,1,1,1">
                    <h:layout>
                        <h:head id="serch" hposition="0,0,*,25" borderwidth="1,1,1,1" style="z-index: 10">
                            <div class="date">
                                <h:editdroplist id="yearEdit" textdatatemplet="{=Name}" textisreadonly="readonly">
                                    <h:itemtemplet>
											&nbsp;{=Name} 年
									</h:itemtemplet>
                                </h:editdroplist>
                            </div>
                            <div style="float: left;">
                                <h:btn id="yearViewBtn">年视图</h:btn>
                            </div>
                            <div class="txt">
                                <div id="OptListPanel">
                                   <h:listview id="OptList" ismultiselect="true">
                                        <h:itemtemplet>
                                       {=Name}
                                    </h:itemtemplet>
                                    </h:listview>
                                </div>
                              <!--  <h:text text="">
                                </h:text><h:btn>搜索</h:btn>-->
                            </div>
                        </h:head>
                        <h:bottom hposition="0,0,*,*" borderwidth="0,0,0,0">
                            <h:layout>
                                <h:left id="month" hposition="0,0,140,*" borderwidth="1,1,1,1" style="overflow: auto;
                                    background-color: White;">
                                    <h:listview id="MonthList" isunselectedinonclick="false">
                                        <h:itemtemplet>
												{=Name}月&nbsp;&nbsp;
												<div style="position: absolute; font-size: 11px; text-align: left; margin-left: 10px;
                                                    margin-top: -8px; font-family: 微软雅黑;">
                                                    支出：1222<br />
                                                    收入：1223
                                                </div>
										</h:itemtemplet>
                                    </h:listview>
                                </h:left>
                                <h:vsplitter id="monthVsplitter" borderwidth="0,0,0,0" hposition="0,0,0,*">
                                </h:vsplitter>
                                <h:right style="background-color: White;">
                                    <h:layout id="billListLayout">
                                        <h:head id="content" hposition="0,0,*,*" borderwidth="1,1,1,1">
                                            <h:grid layoutid="billListLayout" id="billGrid" rowheight="25" ismultiselect="false"
                                                isunselectedinonclick="false">
                                                <h:gridcolumn width="120" isdraging="false">
                                                    <h:headertemplet>
														日期
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=CDateStr}
												  </h:datatemplete>
                                                </h:gridcolumn>
                                                <h:gridcolumn width="55" isdraging="false">
                                                    <h:headertemplet>
														操作
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=OperationName}
												  </h:datatemplete>
                                                </h:gridcolumn>
                                                <h:gridcolumn width="80" isdraging="false">
                                                    <h:headertemplet>
														金额(元)
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=Money}元
												  </h:datatemplete>
                                                </h:gridcolumn>
                                                <h:gridcolumn width="180" isdraging="false">
                                                    <h:headertemplet>
														分类名称
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=CategoryName}
												  </h:datatemplete>
                                                </h:gridcolumn>
                                                <h:gridcolumn width="80" isdraging="false">
                                                    <h:headertemplet>
														帐户
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=AccountName}
												  </h:datatemplete>
                                                </h:gridcolumn>
                                                <h:gridcolumn isdraging="false">
                                                    <h:headertemplet>
														描述
												  </h:headertemplet>
                                                    <h:datatemplete>
														{=Description}
												  </h:datatemplete>
                                                </h:gridcolumn>
                                            </h:grid>
                                        </h:head>
                                        <h:bottom id="page" hposition="0,0,*,30" borderwidth="1,1,1,1">
                                            <div style="padding-top: 3px;">
                                                <h:pagesplitter id="psplitter" pagesize="50">
                                                </h:pagesplitter>
                                            </div>
                                        </h:bottom>
                                    </h:layout>
                                </h:right>
                            </h:layout>
                        </h:bottom>
                    </h:layout>
                </h:right>
            </h:layout>
        </h:bottom>
    </h:layout>
    <h:windows>
    </h:windows>
    <h:window id="modelWindow" type="m" hposition="0,0,350,250" closeenable="false">
        <h:caption>
        </h:caption>
        <h:content>
            <div id="logcontent" style="padding-left: 20px;">
                <br />
                <br />
                &#12288;电子邮箱：<h:text id="logEmail"></h:text><br />
                <br />
                &#12288;&#12288;密&#12288;码：<h:text id="logPsw"></h:text><br />
                <br />
                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;<h:btn id="logOk" keygroup="modelWindow"
                    keychar="Enter">登 录 (Enter) </h:btn>&nbsp;<h:btn id="logGoRegist">我还没有注册</h:btn>
            </div>
            <div id="regcontent" style="padding-left: 20px; background-color: White;">
                <br />
                <br />
                &#12288;电子邮箱：<h:text id="regEmail"></h:text><br />
                <br />
                &#12288;&#12288;密&#12288;码：<h:text id="regPsd"></h:text><br />
                <br />
                &#12288;再次密码：<h:text id="regPsd2"></h:text><br />
                <br />
                &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;<h:btn id="regOk" keychar="Enter"
                    keygroup="regcontent">确定 (Enter)</h:btn>&nbsp;<h:btn id="returnLogin" keychar="ESC"
                        keygroup="regcontent">返回登录 (Esc)</h:btn>
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                dddddddd
                <br />
                <br />
                <br />
                <br />
                dddddddddddddddddddd
            </div>
        </h:content>
    </h:window>
    <p style="text-align: center">
        &nbsp;
    </p>
</body>
<script type="text/javascript">
    var Index = {};
    Index.Init = function () {
        //Begin define Control and Set default
        _g("#OperationEidt").SetWidth(140);
        _g("#CategoryEdit").SetWidth(140);
        _g("#AccountEdit").SetWidth(140);
        _g("#MoneyTxt").SetWidth(138);
        _g("#ProjectEdit").SetWidth(140);
        _g("#MarkTxt").SetHeight(120);
        _g("#MarkTxt").SetWidth(174);
        //End define Control and Set default value

        _g("#OutAccountEdit").SetWidth(180);
        _g("#InAccountEdit").SetWidth(180);
        _g("#TransferMoneyTxt").SetWidth(178);
    };

    var AddBillMsg = _g("#addBillMsg");
    AddBillMsg.txt = _g("#addBillMsgText");
    AddBillMsg.hidTimeOut = null;
    AddBillMsg.Show = function (txt) {
        AddBillMsg.style.display = "";
        AddBillMsg.txt.innerHTML = txt;
        AddBillMsg.style.height = "0px";
        AddBillMsg.Animate({ height: "0,40" }, Theme.AnimateOut, Theme.AnimateDuration, function (sender) {
            if (AddBillMsg.hidTimeOut != null)
                window.clearTimeout(AddBillMsg.hidTimeOut);
            AddBillMsg.hidTimeOut = window.setTimeout(AddBillMsg.Hid, 1000);
        });
    };
    AddBillMsg.Hid = function () {
        AddBillMsg.Animate({ height: "40,0" }, Theme.AnimateIn, Theme.AnimateDuration, function (sender) {
            sender.style.display = "none";
        });
    };
    var transferMsg = _g("#transferMsg");
    transferMsg.txt = _g("#transferMsgText");
    transferMsg.hidTimeOut = null;
    transferMsg.Show = function (txt) {
        transferMsg.style.display = "";
        transferMsg.txt.innerHTML = txt;
        transferMsg.style.height = "0px";
        transferMsg.Animate({ height: "0,40" }, Theme.AnimateOut, Theme.AnimateDuration, function (sender) {
            if (transferMsg.hidTimeOut != null)
                window.clearTimeout(transferMsg.hidTimeOut);
            transferMsg.hidTimeOut = window.setTimeout(transferMsg.Hid, 1000);
        });
    };

    transferMsg.Hid = function () {
        transferMsg.Animate({ height: "40,0" }, Theme.AnimateIn, Theme.AnimateDuration, function (sender) {
            sender.style.display = "none";
        });
    };


    //#region billGrid
    var billGridSearch = function () {
        var yearEdit = _g("#yearEdit");
        var MonthList = _g("#MonthList");

        var currentPage = psplitter.CurrentPage;
        if (currentPage < 0) currentPage = 0;
        var data = {
            year: yearEdit.GetSelect().Value,
            month: MonthList.GetSelect()[0].data.Value,
            operations: billGrid.Where.GetSelectedOperationIdsToStr(),
            projects: billGrid.Where.GetSelectedProjectsIdsToStr(),
            accounts: billGrid.Where.GetSelectedAccontIdsToStr()
        };
        billGrid.OnRowBinding = function (grid, i) {
            grid.Data[i].CDateStr = grid.Data[i].CDate.Format("YYYY/MM/dd");
        };

        //alert(JSON.stringify(data));

        _h.ajax.getJSONP(_h.ResolveClientUrl("~/Data/GetBillDetails"), data, function (rh) {
            if (rh["Error"] == -1) { alert(rh["Data"]); return; }
            var billDatas = rh["Data"];
            var total = rh["Error"];
            if (total <= 0) {
                psplitter.style.display = "none";
            }
            else {
                psplitter.Total = total;
                psplitter.Bind();
                psplitter.style.display = "";
            }
            _h.Grid.Bind(billGrid, billDatas, true, function () {
                _h.Grid.SetRowCss(billGrid, 0, "billGridRowcss");
            });
        });
    };
    //#endregion billGrid

    Index.Load = function (fn) {
        //Load Page Data and Bind to Control.
        //load addBill Data
        if (DataProvider.GetUser() == null) {
            modelWindow.ShowLogin();
            _g("#body").style.display = "";
            return;
        }

        var currentdate = new Date();
        var yearEdit = _g("#yearEdit");
        yearEdit.SetWidth(138);
        yearEdit.Bind(DataProvider.GetYearDatas());
        yearEdit.SetValue(currentdate.getFullYear());

        var MonthList = _g("#MonthList");
        MonthList.Bind(DataProvider.GetMonthDatas(), true, function () {
            MonthList.Select(currentdate.getMonth());
        });

        _h.ajax.getJSONP(_h.ResolveClientUrl("~/Html/Index"), null, function (rh) {
            if (rh["Error"]) { alert(rh["ErrorMsg"]); return; }

            var User = DataProvider.GetUser();
            _g("#UserNameLab").innerHTML = User.LoginEmail;
            var opt = _g("#OperationEidt");
            var cge = _g("#CategoryEdit");
            var acc = _g("#AccountEdit");
            var pro = _g("#ProjectEdit");
            var outAcc = _g("#OutAccountEdit");
            var inAcc = _g("#InAccountEdit");

            var ProjectList = _g("#ProjectList");
            var AccountList = _g("#AccountList");
            var OptList = _g("#OptList");
            opt.Bind(DataProvider.OprerationsInCreateBill);
            opt.SetValue("支出");
            cge.Bind(rh["Categorys"]);
            acc.Bind(rh["Accounts"]);
            acc.SetValue("现金口贷");
            outAcc.Bind(rh["Accounts"]);
            outAcc.SetValue("现金口贷");
            inAcc.Bind(rh["Accounts"]);
            inAcc.SetValue("现金口贷");
            pro.Bind(rh["Projects"]);
            pro.SetValue("个人记帐");
            ProjectList.Bind(rh["Projects"], true, function () {
                AccountList.Bind(rh["Accounts"], true, function () {
                    OptList.Bind(DataProvider.Oprerations, true, function () {
                        billGridSearch();
                    });
                });
            });
            
           
          
            if (fn != null)
                fn();
        });

        //load bills data
        _g("#body").style.display = "";
        //End Init Page Data and Bind to Control
    };

    //当页面加载完成后执行的方法。
    _h.Page.OnLoadHandle = function () {
        Theme.ReLoadShare();
        Theme.ReLoadIndexCss();
        InitMnav();
        var OperationEidt = _g("#OperationEidt");
        var CategoryEdit = _g("#CategoryEdit");
        var AccountEdit = _g("#AccountEdit");
        var MoneyTxt = _g("#MoneyTxt");
        var ProjectEdit = _g("#ProjectEdit");
        var MarkTxt = _g("#MarkTxt");
        var addBillContent = _g("#addBillContent");
        var CreateTransferAccounts = _g("#CreateTransferAccounts");
        var psplitter = _g("#psplitter");
        var billGrid = _g("#billGrid");
        var OptList = _g("#OptList");
        var ProjectList = _g("#ProjectList");
        var AccountList = _g("#AccountList");

        //#region init Where
        billGrid.Where = {};
        billGrid.Where._data = null;
        billGrid.Where.Init = function () {
            var data = billGrid.Where._load();
            if (billGrid.Where._data == null && data == null) {
                billGrid.Where._data = {};
                billGrid.Where._save();
            }
            else {
                billGrid.Where._data = data;
            }

        };
        billGrid.Where.GetPageIndex = function () {
            if (_h.IsNull(billGrid.Where._data.pageIndex)) {
                return 0;
            }
            return billGrid.Where._data.pageIndex;
        };
        billGrid.Where.SetPageIndex = function (pageIndex) {
            billGrid.Where._data.pageIndex = pageIndex;
            billGrid.Where._save();
        };
        billGrid.Where.GetSeletedProjects = function () {
            if (_h.IsNull(billGrid.Where._data.seletedProjects)) {
                return new Array();
            }

            return JSON.parse(billGrid.Where._data.seletedProjects);
        };
        billGrid.Where.SetSeletedProjects = function (projectsArray) {
            if (_h.IsNull(projectsArray) == false && _h.isArray(projectsArray)) {
                billGrid.Where._data.seletedProjects = JSON.stringify(projectsArray);
                billGrid.Where._save();
            }
            else
                alert("billGrid.Where.SetSeletedProjects(array)");
        };
        billGrid.Where.GetSelectedProjectsIdsToStr = function () {
            var listDatas = _g("#ProjectList").Data;
            var selectObjs = billGrid.Where.GetSeletedProjects();
            var arr = new Array();
            for (var i in selectObjs) {
                arr.push(listDatas[selectObjs[i]].ProjectId);
            }
            return arr.join(",");
        };
        billGrid.Where.GetSeletedOperations = function () {
            if (_h.IsNull(billGrid.Where._data.selectedOprations)) {
                return new Array();
            }

            return JSON.parse(billGrid.Where._data.selectedOprations);
        };
        billGrid.Where.SetSeletedOperations = function (oprationsArray) {
            if (_h.IsNull(oprationsArray) === false && _h.isArray(oprationsArray)) {
                billGrid.Where._data.selectedOprations = JSON.stringify(oprationsArray);
                billGrid.Where._save();
            }
            else
                alert("billGrid.Where.SetSeletedOperations(array)");
        };
        billGrid.Where.GetSelectedOperationIdsToStr = function () {
            var listDatas = _g("#OptList").Data;
            var selectObjs = billGrid.Where.GetSeletedOperations();
            var arr = new Array();
            for (var i in selectObjs) {
                arr.push(listDatas[selectObjs[i]].BillOperationId);
            }
            return arr.join(",");
        };
        billGrid.Where.GetSelectedAcconts = function () {
            if (_h.IsNull(billGrid.Where._data.selectedAcconts)) {
                return new Array();
            }
            return JSON.parse(billGrid.Where._data.selectedAcconts);
        };
        billGrid.Where.SetSelectedAcconts = function (selectedAcconts) {
            if (_h.IsNull(selectedAcconts) == false && _h.isArray(selectedAcconts)) {
                billGrid.Where._data.selectedAcconts = JSON.stringify(selectedAcconts);
                billGrid.Where._save();
            }
            else
                alert("billGrid.Where.SetSelectedAcconts(array)");
        };
        billGrid.Where.GetSelectedAccontIdsToStr = function() {
            var listDatas = _g("#AccountList").Data;
            var selectObjs = billGrid.Where.GetSelectedAcconts();
            var arr = new Array();
            for (var i in selectObjs) {
                arr.push(listDatas[selectObjs[i]].AccountId);
            }
            return arr.join(",");
        }

        billGrid.Where._load = function () {
            return JSON.parse(_h.Store.get("BillGridWhereFromIndex"));
        };
        billGrid.Where._save = function () {
            _h.Store.set("BillGridWhereFromIndex", JSON.stringify(billGrid.Where._data));
        };
        billGrid.Where.Init();
        OptList.OnBindCompleted = function (sender) {
            var seletedObjs = billGrid.Where.GetSeletedOperations();
            if (!_h.IsNull(seletedObjs)) {
                var arry = new Array();
                for (var i in seletedObjs) {
                    if (OptList.Select(seletedObjs[i])) {
                        arry.push(seletedObjs[i]);
                    }
                }
                billGrid.Where.SetSeletedOperations(arry);
            }
        };
        OptList.OnItemClick = function (sender, obj, index) {
            var selects = sender.GetSelect();
            var arr = new Array();
            for (var i in selects) {
                arr.push(selects[i].index);
            }
            billGrid.Where.SetSeletedOperations(arr);
            billGridSearch();
        };
        ProjectList.OnBindCompleted = function (sender) {
            var selectedProjects = billGrid.Where.GetSeletedProjects();
            if (!_h.IsNull(selectedProjects)) {
                var tempArray = new Array();
                for (var i in selectedProjects) {
                    if (ProjectList.Select(selectedProjects[i])) {
                        tempArray.push(selectedProjects[i]);
                    }
                }
                billGrid.Where.SetSeletedProjects(tempArray);
            }
        };
        ProjectList.OnItemClick = function (sender, obj, index) {
            var selects = sender.GetSelect();
            var arr = new Array();
            for (var i in selects) {
                arr.push(selects[i].index);
            }
            billGrid.Where.SetSeletedProjects(arr);
            billGridSearch();
        };
        AccountList.OnBindCompleted = function (sender) {
            var selectedObjs = billGrid.Where.GetSelectedAcconts();
            if (!_h.IsNull(selectedObjs)) {
                var tempArray = new Array();
                for (var i in selectedObjs) {
                    if (AccountList.Select(selectedObjs[i])) {
                        tempArray.push(selectedObjs[i]);
                    }
                }
                billGrid.Where.SetSelectedAcconts(tempArray);
            }
        }
        AccountList.OnItemClick = function (sender, obj, index) {
            var selects = sender.GetSelect();
            var arr = new Array();
            for (var i in selects) {
                arr.push(selects[i].index);
            }
            billGrid.Where.SetSelectedAcconts(arr);
            billGridSearch();
        }


        //#endregion init Where
        var yearEdit = _g("#yearEdit");
        var MonthList = _g("#MonthList");
        var yearViewBtn = _g("#yearViewBtn");
        var monthLayout = _g("#month");
        var monthVsplitter = _g("#monthVsplitter");
        var leftVsplitter = _g("#leftVsplitter");
        var hidleftbtn = _g("#hidleftbtn");

        yearEdit.SelectedHandle = function (e) {
            if (MonthList.IsBind)
                billGridSearch();
        };
        MonthList.OnItemClick = function (sender, obj, index) {
            if (!sender.Items[index].Selected) return;
            billGridSearch();
        };
        _h.addEvent(yearViewBtn, "click", function () {
            if (monthVsplitter.IsHid()) {
                yearViewBtn.innerHTML = "年视图";
                monthVsplitter.Show();
            }
            else {
                yearViewBtn.innerHTML = "月视图";
                monthVsplitter.Hid();
            }
        });
        _h.addEvent(hidleftbtn, "click", function () {
            leftVsplitter.SetHposition("0,0,32,0");
            leftVsplitter.Hid();
        });
        _h.addEvent(_g("#showleftbtn"), "click", function () {
            leftVsplitter.SetHposition("0,0,0,0");
            leftVsplitter.Show();
        });
        addBillContent.IsShow = false;
        addBillContent.Show = function () {
            addBillContent.IsShow = true;
            if (CreateTransferAccounts.IsShow) {
                CreateTransferAccounts.Hid(function () {
                    _h.key.ActiveGroup("addBillContent");
                });
            }
            _h.key.ActiveGroup("addBillContent");
            var content = _g(".content", this)[0];
            this.style.height = "0px";
            this.style.display = "";
            _g("#addBillbtn").Active("true");
            addBillContent.Init();
            this.Animate({ height: "0,410" }, Theme.AnimateOut, Theme.AnimateDuration);
        };
        addBillContent.Hid = function (completed) {
            addBillContent.IsShow = false;
            var content = _g(".content", this)[0];
            //content.style.display = "none";
            this.Animate({ height: "410,0" }, Theme.AnimateIn, Theme.AnimateDuration, function (sender) {
                _g("#addBillbtn").Active("false");
                _h.key.ActiveGroup("default");
                addBillContent.style.display = "none";
                if (completed != null)
                    completed();
            });
        };
        addBillContent.Init = function () {
            MoneyTxt.txt.focus();
            CategoryEdit.SetValue("");
            MoneyTxt.SetText("");
        };

        CreateTransferAccounts.IsShow = false;
        CreateTransferAccounts.Show = function () {
            CreateTransferAccounts.IsShow = true;
            if (addBillContent.IsShow) {
                addBillContent.Hid(function () {
                    _h.key.ActiveGroup("CreateTransferAccounts");
                });
            }
            _h.key.ActiveGroup("CreateTransferAccounts");
            var content = _g(".content", this)[0];
            this.style.height = "0px";
            this.style.display = "";
            _g("#transferBillbtn").Active("true");
            CreateTransferAccounts.Init();
            this.Animate({ height: "0,290" }, Theme.AnimateOut, Theme.AnimateDuration);
        };
        CreateTransferAccounts.Hid = function (completed) {
            CreateTransferAccounts.IsShow = false;
            var content = _g(".content", this)[0];
            //content.style.display = "none";
            this.Animate({ height: "290,0" }, Theme.AnimateIn, Theme.AnimateDuration, function (sender) {
                _g("#transferBillbtn").Active("false");
                _h.key.ActiveGroup("default");
                CreateTransferAccounts.style.display = "none";
                if (completed != null)
                    completed();
            });
        };
        CreateTransferAccounts.Init = function () {
            //MoneyTxt.txt.focus();
            //CategoryEdit.SetValue("");
            //MoneyTxt.SetText("");
        };
        _h.addEvent(_g("#transferBillbtn"), "click", function () {
            CreateTransferAccounts.Show();
        });
        Index.Init();
        //#region this code are enter login window
        var modelWindow = _g("#modelWindow");
        modelWindow.ShowLogin = function () {
            this.SetPosition("0,0,350,250");
            this.SetCaption("&#12288;欢迎来到 Finace");
            this.Show();
            _g("#logcontent").style.display = "";
            _g("#regcontent").style.display = "none";
            var email = _g("#logEmail");
            email.txt.focus();

        };
        modelWindow.ShowRegist = function () {
            this.SetPosition("0,0,350,450");
            this.SetCaption("&#12288;欢迎加入到 Finace！");
            this.Show();
            _g("#logcontent").style.display = "none";
            _g("#regcontent").style.display = "";
            var regEmail = _g("#regEmail");
            regEmail.SetText("");
            regEmail.txt.focus();
            _g("#regPsd").SetText("");
            _g("#regPsd2").SetText("");
        };
        //#endregion enter login window

        //#region this is code about regist user
        _h.addEvent(_g("#regOk"), "click", function () {
            var regEmail = _g("#regEmail");
            var regPsd = _g("#regPsd");
            var regPsd2 = _g("#regPsd2");
            if (regEmail.GetText() == "") { alert("请输入登录 Email。"); return; }
            if (regPsd.GetText() == "") { alert("请输入密码。"); return; }
            if (regPsd2.GetText() == "") { alert("请再输入一次密码。"); return; }
            if (regPsd.GetText() != regPsd2.GetText()) { alert("两次输入的密码不匹配，请合对后重新输入。"); return; }
            var user = { LoginEmail: regEmail.GetText(), Password: regPsd.GetText() };
            var requestData = { userJson: JSON.stringify(user) };
            _h.ajax.getJSONP(_h.ResolveClientUrl("~/Data/RegistUser"), requestData, function (rh) {
                if (rh["Error"] == -1) { alert(rh["Data"]); return; }
                _h.key.ActiveGroup();
                modelWindow.ShowLogin();
            });
        });
        _h.addEvent(_g("#logGoRegist"), "click", function () {
            modelWindow.ShowRegist();
            _h.key.ActiveGroup("regcontent");
        });
        _h.addEvent(_g("#returnLogin"), "click", function () {
            _h.key.ActiveGroup();
            modelWindow.ShowLogin();
        });
        //#endregion regist user

        //#region this code is about login system
        _h.addEvent(_g("#logOk"), "click", function () {
            var logEmail = _g("#logEmail");
            var logPsw = _g("#logPsw");
            if (logEmail.GetText() == "") { alert("请输入电子邮箱。"); return; }
            if (logPsw.GetText() == "") { alert("请输入密码。"); return; }
            var param = { loginEmail: logEmail.GetText(), psw: logPsw.GetText() };
            _h.ajax.getJSONP(_h.ResolveClientUrl("~/Data/Login"), param, function (rh) {
                if (rh["Error"] == -1) { alert(rh["Data"]); return; }
                Index.Load(function () { modelWindow.Hid(); });
            });
        });
        //#endregion code is about login system

        //#region this code is about addBill
        _h.addEvent(_g("#addBillbtn"), "click", function () {
            addBillContent.Show();
        });
        _h.addEvent(_g("#addBillEsc"), "click", function () {
            addBillContent.Hid();
        });
        _h.addEvent(_g("#addBillOk"), "click", function () {
            var operationSelect = OperationEidt.GetSelect();
            var categoryValue = CategoryEdit.GetValue();
            var moneyValue = MoneyTxt.GetText();
            var projectValue = ProjectEdit.GetSelect();

            var account = AccountEdit.GetSelect();

            if (categoryValue == "") {
                AddBillMsg.Show("请选择或输入分类。");
                return;
            }

            if (moneyValue == "") {
                AddBillMsg.Show("请输入金额,格式如：0.00");
                return;
            }

            var markValue = MarkTxt.GetText();

            if (markValue == "备注：")
                markValue = "";

            var data = {
                billOperationId: operationSelect.BillOperationId, billCategory: categoryValue,
                money: moneyValue, projectId: projectValue.ProjectId,
                accountId: account.AccountId, description: markValue
            };

            _h.ajax.getJSONP(_h.ResolveClientUrl("~/Data/CreateBill"), data, function (rh) {
                if (rh["Error"]) { alert(rh["ErrorMsg"]); return; }
                if (rh["IsNewCateory"]) {
                    CategoryEdit.Data.push(rh["Category"]);
                    CategoryEdit.Bind(CategoryEdit.Data);
                }
                AddBillMsg.Show("账单添加成功");
                addBillContent.Init();
            });
        });
        //#endregion this code is about addBill
        //#region Transfer Button Event

        _h.addEvent(_g("#TransferOk"), "click", function () {
            var TransferMoneyTxt = _g("#TransferMoneyTxt");
            var transferMoneyValue = TransferMoneyTxt.GetText();
            if (transferMoneyValue == "") {
                transferMsg.Show("请输入转账金额");
            }
            var OutAccountEdit = _g("#OutAccountEdit");
            var outAccountSelect = OutAccountEdit.GetSelect();
            var InAccountEdit = _g("#InAccountEdit");
            var inAccountSelect = InAccountEdit.GetSelect();
            if (outAccountSelect.AccountId == inAccountSelect.AccountId) {
                transferMsg.Show("出与入账帐户相同");
            }

            var data = {
                money: transferMoneyValue,
                outAccount: outAccountSelect.AccountId,
                inAccount: inAccountSelect.AccountId
            };


            _h.ajax.getJSONP(_h.ResolveClientUrl("~/Data/CreateTransferBill"), data, function (rh) {
                if (rh["Error"]) { alert(rh["ErrorMsg"]); return; }
                transferMsg.Show("转账成功");
                CreateTransferAccounts.Init();
            });

        });

        _h.addEvent(_g("#TransferEsc"), "click", function () {
            CreateTransferAccounts.Hid();
        });

        //#endregion
        Index.Load();
    }
</script>
</html>
